using System.Linq;
using Amazon.ECS.Model;
using RomanJendrusz.Amazon.ETL.Domain;
using RomanJendrusz.Amazon.ETL.Infrastructure;

namespace RomanJendrusz.Amazon.ETL.Messages.MessageMappers
{
    public class GetBookListmaniaListsMapper :
        MessageMapper<GetBookListmaniaListsRequest, ItemLookupRequest, ItemLookupResponse>
    {
        public override AmazonResponse MapToAmazonResponse(ItemLookupResponse awsResponse)
        {
            var item = GetRequestItem(awsResponse, 0);
            var listmaniaLists = AssertThat.IsNotNull(item.ListmaniaLists, "ListmaniasResponses");
            var lists = AssertThat.IsNotNull(listmaniaLists.ListmaniaList, "ListmaniaLists");
            var listmanias = from list in lists
                                select new ListMania {ListId = list.ListId, ListName = list.ListName};
            return new GetBookListmaniaListsResponse(CorrelationId) {ListManias = listmanias.ToList()};
        }

        public override ItemLookupRequest MapToAwsRequest(GetBookListmaniaListsRequest request)
        {
            var awsRequest = new ItemLookupRequest
                                 {
                                     MerchantId = request.MerchantId,
                                     //IdType = "ISBN",
                                     //SearchIndex = "Books"
                                 };
            awsRequest.ResponseGroup.Add(request.ResponseGroup);
            awsRequest.MerchantId = request.MerchantId;
            return awsRequest;
        }
    }
}